/******************************************************************************
 * <p>
 * File: highScore.java
 * </p>
 * @author  Mike Slomon
 * @author <a href="mailto:blackstar138@gmail.com">Email Mike</a>
 * @version 1.0, 2007
 * @created 
 * @revised 
 * 
 * 	<p>
 * 	Description: HighScores class used for sending highscores from the game to the highscore database
 * 	using a get request. Takes name and score arguments.
 * </p>
 *  
 *  This file is part of Retribution.
 *
 *  Retribution is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Retribution is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Retribution; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *   
 *****************************************************************************/
import java.net.*;
import java.io.*;
public class highScore {

	/**
	 * @param name Name of Player
	 * @param score Score player acheived
	 * Method takes Name and Score parameters
	 * Creates URL request and sends GET request to PHP request page
	 * Name and Score stored in SQL Database
	 */
	public void sendScore(String name, String score){
		try {	 
			
				//create new URL for GET request
			 	URL url = new URL("http://csserver.ucd.ie/~s04bf1d5/retribution/insert.php?name="+name+"&score="+score);
			 	//System.out.println(url);
			 	URLConnection connection = url.openConnection();
			 	if (connection instanceof HttpURLConnection) {
			 		HttpURLConnection httpConnection = (HttpURLConnection)connection;
			 		httpConnection.setRequestMethod("GET");
			 		httpConnection.setDoOutput(true);
			 		httpConnection.connect();
			 		
			 		/**
			 		 * read in response from server
			 		 * Response code 200 = Request Recieved
			 		 * If request not recieved ok, print error
			 		 */
			 		int response = httpConnection.getResponseCode();
			 		if(response != 200){
			 			System.out.println("Response: " + response);
			 			InputStream is = httpConnection.getInputStream();
			 			System.out.println(is);
					 	System.out.println("length "+httpConnection.getContentLength());
			 		}
				 	
			 	}
		        
		    } catch (Exception e) {
		 }
	}

}
